using Microsoft.AspNetCore.Mvc;
using Lzfy_Refund_Service.Models;
using Lzfy_Refund_Service.Services;

namespace Lzfy_Refund_Service.Controllers
{
    /// <summary>
    /// 患者数据查询控制器
    /// </summary>
    //[ApiController]
    [Route("api/[controller]")]
    public class PatientDataController : ControllerBase
    {
        private readonly IPatientDataQueryService _patientDataQueryService;
        private readonly ILogger<PatientDataController> _logger;

        public PatientDataController(
            IPatientDataQueryService patientDataQueryService,
            ILogger<PatientDataController> logger)
        {
            _patientDataQueryService = patientDataQueryService;
            _logger = logger;
        }

        // 接口已禁用 - 2024年1月
        // 原因：临时停用患者数据查询接口，禁止客户端访问
        /*
        /// <summary>
        /// 根据用户ID查询最新的患者数据
        /// </summary>
        /// <param name="request">查询请求</param>
        /// <returns>患者数据</returns>
        [HttpPost("query-latest-patient-data")]
        public async Task<ActionResult<PatientDataQueryResponse>> QueryLatestPatientData([FromBody] PatientDataQueryRequest request)
        {
            try
            {
                _logger.LogInformation("接收到患者数据查询请求，用户ID: {UserId}", request.UserId);
                
                // 参数验证
                if (string.IsNullOrWhiteSpace(request.UserId))
                {
                    _logger.LogWarning("用户ID不能为空");
                    return BadRequest(new PatientDataQueryResponse
                    {
                        Success = false,
                        Message = "用户ID不能为空"
                    });
                }
                
                // 调用服务查询数据
                var result = await _patientDataQueryService.QueryAndMigratePatientDataAsync(request.UserId);
                
                if (result.Success)
                {
                    _logger.LogInformation("患者数据查询成功，用户ID: {UserId}", request.UserId);
                    return Ok(result);
                }
                else
                {
                    _logger.LogInformation("患者数据查询失败，用户ID: {UserId}, 原因: {Message}", 
                        request.UserId, result.Message);
                    return NotFound(result);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "患者数据查询异常，用户ID: {UserId}", request.UserId);
                return StatusCode(500, new PatientDataQueryResponse
                {
                    Success = false,
                    Message = "服务器内部错误"
                });
            }
        }
        */
    }
}